home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / DSAT_ANA / DSAT_ANA.C next >
C/C++ Source or Header  |  1988-11-02  |  6KB  |  253 lines

  1. /*
  2.     System error alert table analyzer
  3.     "DSAT Analyzer.c"
  4. */
  5.  
  6. #include "DSAT.h"
  7.  
  8. /* ----- Globals ------------------------------------------------------- */
  9.  
  10. TABLE_PTR    TablePtr;        /* Pointer to current alert table */
  11. long        TableSize;        /* Size in bytes of current alert table */
  12. TYPE_PTR    What;            /* Information array associated to table */
  13. int            DSAT_id;        /* Current id of 'DSAT' resource */
  14. int            Proc_id = 0;    /* Id for procedure resources */
  15. int            Icon_id = 0;    /* Id for icon resources */
  16.  
  17. /* ----- Set definition type ------------------------------------------- */
  18.  
  19. static int Definition;
  20. static int Stamp;
  21.  
  22. int Pass_Stamp(i, p)
  23. int i;
  24. DEFINITION_PTR p;
  25. {
  26.     if (p->u.id != Definition)
  27.         return 0;
  28.     if (What[i].type == type_unknown) {
  29.         What[i].type = Stamp;
  30.         return 1;
  31.     }
  32.     return 0;
  33. }
  34.  
  35. void FindandStamp(id, type)
  36. int id;
  37. int type;
  38. {
  39.     Definition = id;
  40.     Stamp = type;
  41.     ScanTable(TablePtr, TableSize, &Pass_Stamp);
  42. }
  43.  
  44. /* ----- Find alert definitions ---------------------------------------- */
  45.  
  46. int Pass_Alerts1(i, p)
  47. int i;
  48. DEFINITION_PTR p;
  49. {
  50.     What[i].type = (p->u.length == 10) ? type_alert : type_unknown;
  51.     What[i].flag = 0;
  52.     What[i].definition = p;
  53.     return 0;
  54. }
  55.  
  56. /* ----- Explore alert definitions ------------------------------------- */
  57.  
  58. int Pass_Alerts2(i, p)
  59. int i;
  60. DEFINITION_PTR p;
  61. {
  62.     if (What[i].type != type_alert)
  63.         return 0;
  64.     FindandStamp(p->a.text1, type_text);
  65.     FindandStamp(p->a.text2, type_text);
  66.     FindandStamp(p->a.icon, type_icon);
  67.     FindandStamp(p->a.code, type_code);
  68.     FindandStamp(p->a.button, type_button);
  69.     return 0;
  70. }
  71.  
  72. /* ----- Explore button definitions ------------------------------------ */
  73.  
  74. int Pass_Buttons1(i, p)
  75. int i;
  76. DEFINITION_PTR p;
  77. {
  78.     register int j, n;
  79.  
  80.     if (What[i].type != type_button)
  81.         return 0;
  82.     n = p->b.buttons;
  83.     for (j = 0; j < n; j++) {
  84.         FindandStamp(p->b.button[j].string, type_string);
  85.         FindandStamp(p->b.button[j].code, type_code);
  86.     }
  87.     return 0;
  88. }
  89.  
  90. /* ----- Find resume buttons ------------------------------------------- */
  91.  
  92. int Pass_Buttons2(i, p)
  93. int i;
  94. DEFINITION_PTR p;
  95. {
  96.     if (What[i].type != type_button)
  97.         return 0;
  98.     FindandStamp(p->b.id + 1, type_button);
  99.     return 0;
  100. }
  101.  
  102. /* ----- Print detail about each definition ---------------------------- */
  103.  
  104. static char *Types[] = {
  105.     "?     ", "ALERT ", "TEXT  ", "ICON  ",
  106.     "BUTTON", "STRING", "CODE  "
  107. };
  108.  
  109. void Detail(i)
  110. register int i;
  111. {
  112.     register DEFINITION_PTR p;
  113.     register int j, n;
  114.     register char line[256];
  115.  
  116.     p = What[i].definition;
  117.     switch(What[i].type) {
  118.         case type_alert:
  119.             sprintf(line,
  120.                 "text=%d text=%d icon=%d code=%d button=%d\r",
  121.                 p->a.text1, p->a.text2, p->a.icon, p->a.code, p->a.button);
  122.             Output(line);
  123.             break;
  124.         case type_text:
  125.             sprintf(line, "point=(%d,%d) \"%s\"\r",
  126.                 p->t.location.v, p->t.location.h, p->t.text);
  127.             Output(line);
  128.             break;
  129.         case type_icon:
  130.             sprintf(line, "DSAT=%d id=%d", DSAT_id, p->i.id);
  131.             CtoPstr(line);
  132.             OutputResource(p->i.icon, 128L, 'ICON', Icon_id, line);
  133.             {
  134.                 long iconList[64];
  135.  
  136.                 BlockMove(p->i.icon, iconList, 128L);
  137.                 for (j = 32; j < 64; j++)
  138.                     iconList[j] = -1L;
  139.                 OutputResource(iconList, 256L, 'ICN#', Icon_id, line);
  140.             }
  141.             Icon_id++;
  142.             sprintf(line, "rect=(%d,%d,%d,%d)\r",
  143.                 p->i.location.top, p->i.location.left,
  144.                 p->i.location.bottom, p->i.location.right);
  145.             Output(line);
  146.             break;
  147.         case type_button:
  148.             n = p->b.buttons;
  149.             sprintf(line, "buttons=%d", n);
  150.             Output(line);
  151.             for (j = 0; j < n; j++) {
  152.                 sprintf(line, "  string=%d rect=(%d,%d,%d,%d) code=%d",
  153.                     p->b.button[j].string,
  154.                     p->b.button[j].location.top,
  155.                     p->b.button[j].location.left,
  156.                     p->b.button[j].location.bottom,
  157.                     p->b.button[j].location.right,
  158.                     p->b.button[j].code);
  159.                 Output(line);
  160.             }
  161.             Output("\r");
  162.             break;
  163.         case type_string:
  164.             n = p->s.length;
  165.             BlockMove(p->s.string, line+1, (long)n);
  166.             line[0] = '"';
  167.             line[n+1] = '"';
  168.             line[n+2] = '\r';
  169.             line[n+3] = '\0';
  170.             Output(line);
  171.             break;
  172.         case type_code:
  173.             sprintf(line, "DSAT=%d id=%d", DSAT_id, p->c.id);
  174.             CtoPstr(line);
  175.             OutputResource(p->c.code, (long)(p->c.length),
  176.                 'PROC', Proc_id++, line);
  177.             Output("\r");
  178.             break;
  179.         default:
  180.             Output("\r");
  181.             break;
  182.     }
  183. }
  184.  
  185. int Pass_Description(i, p)
  186. int i;
  187. DEFINITION_PTR p;
  188. {
  189.     char line[256];
  190.  
  191.     sprintf(line, "%2d.%6d (%3d) %s  ",
  192.         i, p->u.id, p->u.length, Types[What[i].type]);
  193.     Output(line);
  194.     Detail(i);
  195.     return 0;
  196. }
  197.  
  198. /* ----- main program -------------------------------------------------- */
  199.  
  200. void main()
  201. {
  202.     register int i, k;
  203.     register Handle h;
  204.     SFReply sfr;
  205.     long rType;
  206.     Str255 name;
  207.  
  208.     MaxApplZone();
  209.     InitGraf(&thePort);
  210.     InitFonts();
  211.     InitWindows();
  212.     InitMenus();
  213.     TEInit();
  214.     InitDialogs(0L);
  215.     FlushEvents(-1, 0);
  216.  
  217.     SFPutFile((80L<<16) + 80L, "\pSave file as:", "\pDSAT list", 0L, &sfr);
  218.     if (!sfr.good)
  219.         return;
  220.     SetCursor(*GetCursor(watchCursor));
  221.     if (OutputOpen(sfr.fName, sfr.vRefNum)) {
  222.         SysBeep(1);
  223.         return;
  224.     }
  225.     Output("SYSTEM ERROR ALERT TABLES\r");
  226.     i = 1;
  227.     do
  228.         if (h = GetIndResource('DSAT', i)) {
  229.             HLock(h);
  230.             TablePtr = (TABLE_PTR)(*h);
  231.             TableSize = SizeResource(h);
  232.             GetResInfo(h, &DSAT_id, &rType, &name);
  233.             k = ScanTable(TablePtr, TableSize, 0L);
  234.             sprintf(name,
  235.                 "\r'DSAT' id=%d  size=%ld  count=%d\r",
  236.                 DSAT_id, SizeResource(h), k);
  237.             Output(name);
  238.             if (k > 0 && (What = (TYPE_PTR)NewPtr(k * sizeof(TYPE)))) {
  239.                 ScanTable(TablePtr, TableSize, &Pass_Alerts1);
  240.                 ScanTable(TablePtr, TableSize, &Pass_Alerts2);
  241.                 ScanTable(TablePtr, TableSize, &Pass_Buttons1);
  242.                 ScanTable(TablePtr, TableSize, &Pass_Buttons2);
  243.                 ScanTable(TablePtr, TableSize, &Pass_Buttons1);
  244.                 ScanTable(TablePtr, TableSize, &Pass_Description);
  245.                 DisposPtr(What);
  246.             }
  247.             ReleaseResource(h);
  248.             i++;
  249.         }
  250.     while(h);
  251.     OutputClose();
  252. }
  253.